<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>文章管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		var startLine = 0;
		var interv;
		$(document).ready(function() {
			
		});
		
		function spiderLog()
		{
			var clientData = {"startLine":startLine};
			$.ajax({
				url:"${ctx}/cms/spider/spiderLog",
				type:"post",
				async:true,
				data:clientData,
				success:function(data){
					data = eval('(' + data + ')');
					if(data.success){
						startLine = data.startLine;
						var logDiv = $("#logDiv").html();
						var msg = data.data;
						/* if(logDiv)
						{ */
							$("#logDiv").html(logDiv + msg)
						//}
					}else{
						
		            }
				}
			});
		}
		
		function readLog()
		{
			interv = window.setInterval("spiderLog()",5000); 
		}
		
		function startSpider()
		{
			// 爬虫运行时，开始位置清零
			startLine = 0;
			
			$("#logDiv").html("");
			$("#tip").show();
	    	$("#tip").html("<img style='margin-left: 100px;' src='${ctxStatic}/sdlyfp/img/loading-2.gif'/>正在导出数据，请稍后...");
	    	$("#start").attr("disabled",true);
	    	readLog();
	    	var clientData = {};
	    	$.ajax({
				url:"${ctx}/cms/spider/startSpider",
				type:"post",
				async:true,
				timeout : 300000,
				data:clientData,
				success:function(data){
					clearInterval(interv);
					data = eval('(' + data + ')');
					$("#tip").show();
					if(data.success){
						var msg = data.msg;
						$("#tip").html(msg);
					}else{
						$("#tip").html(msg);
		            }
					$("#start").attr("disabled",false);
					
					// 爬虫运行完毕后，直接获取日志
					spiderLog();
				}
			});
		}
		
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/cms/article/?category.id=${article.category.id}">爬虫首页</a></li>
	</ul><br/>
	<input id="start" class="btn btn-primary" type="button" onclick="startSpider();" value="启动爬虫" style="margin-left: 100px;"/>
	</br></br>
	<div style="margin-left: 100px;"> 
		<font color="red" style="font-weight: bold;display: none;" id="tip"></font>
	</div>
	<div style="margin-left: 100px;" id="logDiv"> 
		
	</div>
</body>
</html>